package com.cgs.mongo.delegate;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.mongodb.Block;
import com.mongodb.Function;
import com.mongodb.client.*;
import com.mongodb.client.model.Collation;
import com.mongodb.lang.Nullable;
import org.bson.BsonString;
import org.bson.conversions.Bson;

import java.util.Collection;
import java.util.Map;
import java.util.Spliterator;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import static com.cgs.mongo.utils.WrapperUtils.asBsonDocument;

public class DistinctIterableWrapper implements DistinctIterable<BsonString> {

    private DistinctIterable<BsonString> delegate;

    public DistinctIterableWrapper(DistinctIterable<BsonString> delegate) {
        this.delegate = delegate;
    }

    @Override
    public DistinctIterable<BsonString> filter(Bson filter) {
        return delegate.filter(filter);
    }

    public DistinctIterable<BsonString> filter(Map<String, Object> filter) throws JsonProcessingException {
        return delegate.filter(asBsonDocument(filter));
    }

    @Override
    public DistinctIterable<BsonString> maxTime(long maxTime, TimeUnit timeUnit) {
        return delegate.maxTime(maxTime, timeUnit);
    }

    public DistinctIterable<BsonString> maxTimeSeconds(long maxTime) {
        return delegate.maxTime(maxTime, TimeUnit.SECONDS);
    }

    @Override
    public DistinctIterable<BsonString> batchSize(int batchSize) {
        return delegate.batchSize(batchSize);
    }

    @Override
    public DistinctIterable<BsonString> collation(Collation collation) {
        return delegate.collation(collation);
    }

    @Override
    public MongoCursor<BsonString> iterator() {
        return delegate.iterator();
    }

    @Override
    @Nullable
    public BsonString first() {
        return delegate.first();
    }

    @Override
    public <U> MongoIterable<U> map(Function<BsonString, U> mapper) {
        return delegate.map(mapper);
    }

    @Override
    @Deprecated
    public void forEach(Block<? super BsonString> block) {
        delegate.forEach(block);
    }

    @Override
    public <A extends Collection<? super BsonString>> A into(A target) {
        return delegate.into(target);
    }

    @Override
    public void forEach(Consumer<? super BsonString> action) {
        delegate.forEach(action);
    }

    @Override
    public Spliterator<BsonString> spliterator() {
        return delegate.spliterator();
    }
}
